package com.wz.controller;


import com.wz.entity.Dep;
import com.wz.entity.Empage;
import com.wz.service.impl.DepServiceImpl;
import com.wz.service.impl.EmpageServiceImpl;
import com.wz.util.JFreeChartUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Controller
public class TableController{
    @Autowired
    DepServiceImpl depService;
    @Autowired
    EmpageServiceImpl empageService;

    @RequestMapping("/showtable")
    private String table_show(Model model){
        List<Dep> deps = depService.findDep();
         Map<String, Double> map = new HashMap<>();
        for (Dep dep : deps) {
            map.put(dep.getDepname(),Double.parseDouble(dep.getEmpnum()));
        }
        JFreeChartUtil.createPiePort("部门人数情况图",map,"G:\\Springboot大作业\\springboot-project-master\\springboot-anli\\src\\main\\resources\\static\\table\\饼状图.png");
        model.addAttribute("pieport",map);
        List<Empage> empages=empageService.findEmpage();
        Map<String, Double> map1 = new HashMap<>();
        for (Empage empage : empages) {
            map1.put(empage.getEname(),Double.parseDouble(empage.getAge()));
        }
        JFreeChartUtil.createLinePort("员工年龄情况图",map1,"","员工年龄","G:\\Springboot大作业\\springboot-project-master\\springboot-anli\\src\\main\\resources\\static\\table\\折线图.png");
        model.addAttribute("linePort",map1);
        Map<String, Double> map2 = new HashMap<>();
        for (Empage empage : empages) {
            map2.put(empage.getEname(),Double.parseDouble(empage.getYear()));
        }
        JFreeChartUtil.createBarPort("员工工龄龄情况图",map2,"G:\\Springboot大作业\\springboot-project-master\\springboot-anli\\src\\main\\resources\\static\\table\\柱状图.png");
        model.addAttribute("BarPort",map2);
        System.out.println(map);
        System.out.println(map1);
        System.out.println(map2);;


        return "showtable";


 }
}
